package sge.data;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import sge.beans.Professor;

public class ProfessorDAO {

	private static ProfessorDAO dao;

	private ProfessorDAO() {
	}

	public static ProfessorDAO obterProfessorDAO() {
		if (dao == null) {
			dao = new ProfessorDAO();
		}
		return dao;
	}

	public void inserirProfessor(Professor professor) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(professor);
		} finally {
			pm.close();
		}
	}

	@SuppressWarnings("unchecked")
	public List<Professor> todosProfessores() {
		List<Professor> lista = new ArrayList<Professor>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			Query query = pm.newQuery(Professor.class);
			lista.addAll((List<Professor>) query.execute());
		} finally {
			pm.close();
		}
		return lista;
	}

}
